clear all;
clc;

load mnist_train_all

X = double(data);

clear data;
clear label;

load mnist_test_all

X = [X;double(data)];

clear data;
clear label;

k = 7;

n = size(X,1);

IDX = zeros(n,k);
D = zeros(n,k);

tic
parfor i = 1:n
    if (rem(i,1000) == 0)
        disp(i);
    end
    [IDX(i,:),D(i,:)] = knnsearch(X,X(i,:),'K',k);
end
%[IDX,D] = knnsearch(X,X,'K',k);
toc